﻿using System;
using UnityEngine;

public class Clock : MonoBehaviour
{
    const float DegreesPerHour = 360f / 12;
    const float DegreesPerMinute = 360f / 60;
    const float DegreesPerSecond = 360f / 60;

    public Transform hoursTransform;
    public Transform minutesTransform;
    public Transform secondsTransform;

    public bool continuous;

    void Awake()
    {
        DateTime now = DateTime.Now;

        Debug.Log("Awake is Doing..." + now.Hour);
        Debug.Log("Awake is Doing..." + now.Minute);
        Debug.Log("Awake is Doing..." + now.Second);

        UpdateDiscrete();
    }

    // Start is called before the first frame update
    void Start()
    {
        DateTime now = DateTime.Now;

        Debug.Log("Start is Doing..." + now.Hour);
        Debug.Log("Start is Doing..." + now.Minute);
        Debug.Log("Start is Doing..." + now.Second);
    }

    // Update is called once per frame
    void Update()
    {

        if(this.continuous)
        {
            UpdateContinous();
        } else
        {
            UpdateDiscrete();
        }
    }

    private void UpdateDiscrete()
    {
        DateTime now = DateTime.Now;
        hoursTransform.localRotation = Quaternion.Euler(0f, now.Hour * DegreesPerHour, 0f);
        minutesTransform.localRotation = Quaternion.Euler(0f, now.Minute * DegreesPerMinute, 0f);
        secondsTransform.localRotation = Quaternion.Euler(0f, now.Second * DegreesPerSecond, 0f);
    }

    private void UpdateContinous()
    {
        TimeSpan time = DateTime.Now.TimeOfDay;
        hoursTransform.localRotation = Quaternion.Euler(0f, (float)(time.TotalHours * DegreesPerHour), 0f);
        minutesTransform.localRotation = Quaternion.Euler(0f, (float)(time.TotalMinutes * DegreesPerMinute), 0f);
        secondsTransform.localRotation = Quaternion.Euler(0f, (float)(time.TotalSeconds * DegreesPerSecond), 0f);
    }

}
